package com.wenwen.social.controller;

import com.wenwen.social.application.FollowLineApplication;
import com.wenwen.social.application.HomeLineApplication;
import com.wenwen.social.application.dto.MessageDTO;
import com.wenwen.social.application.dto.PageRequest;
import com.wenwen.social.application.dto.PageResult;
import com.wenwen.social.application.dto.UserDTO;
import com.wenwen.social.common.exception.ServiceException;
import com.wenwen.social.controller.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.wenwen.social.constant.errorcode.CommonErrorConstant.*;

@RestController
public class HomeLineController extends BaseController {

	@Autowired
	private HomeLineApplication homeLineApplication;


	/**
	 * 我的主页动态
	 * test：http://localhost:8080/homeLine?pageNum=1&pageSize=10
	 * @return
	 */
	@GetMapping("/homeLine")
	public PageResult<MessageDTO> queryHomeLine(@Validated PageRequest pageRequest) {
		UserDTO currLoginUser = getCurrLoginUser();
		if(currLoginUser == null) {
			throw new ServiceException(USER_NOT_LOGIN_CODE,USER_NOT_LOGIN_MSG);
		}
		if(currLoginUser.getId() == null){
			throw new ServiceException(USER_NOT_EXIST_CODE,USER_NOT_EXIST_MSG);
		}

		return homeLineApplication.queryHomeLineMsg(pageRequest, currLoginUser.getId());
	}
}
